import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */

export const constantRoutes = [
  // 登录页面
  {
    path: '/login',
    component: () => import('@/views/Login/index.vue'),
    hidden: true
  },
  // 404 页面
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    redirect: '/home',
    component: () => import('@/layout/index.vue'),
    children: [
      {
        path: '/task',
        component: () => import('@/views/task/Task.vue'),
        children: [
          {
            path: 'business',
            component: () => import('@/views/task/Business.vue')
          },
          {
            path: 'operation',
            component: () => import('@/views/task/Operation.vue')
          }
        ]
      },
      { path: 'home', component: () => import('@/views/home/Home.vue') },
      // node
      { path: '/node/node', component: () => import('@/views/node/node.vue') },
      { path: '/node/region', component: () => import('@/views/node/region') },
      { path: '/node/partner', component: () => import('@/views/node/partner.vue') },
      // vm
      { path: '/vm/index', component: () => import('@/views/vm/index.vue') },
      { path: '/vm/status', component: () => import('@/views/vm/status.vue') },
      { path: '/vm/type', component: () => import('@/views/vm/type.vue') },
      // user
      { path: '/user/index', component: () => import ('@/views/user/index.vue') },
      { path: '/user/user-task-stats', component: () => import ('@/views/user/user-task-stats.vue') },
      { path: '/user/user-work', component: () => import ('@/views/user/user-work.vue') },
      // sku
      { path: '/sku/sku-class', component: () => import ('@/views/sku/sku-class.vue') },
      { path: '/sku/sku', component: () => import ('@/views/sku/sku.vue') },
      // 其他
      { path: '/policy/index', component: () => import ('@/views/policy.vue') },
      { path: '/order/index', component: () => import ('@/views/order.vue') },
      { path: '/report/index', component: () => import ('@/views/report.vue') }
    ]
  }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    // mode: "history",
    // scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// reset 路由方法
// export function resetRouter() {
//   // 得到一个全新的 router 实例对象
//   const newRouter = createRouter();
//   // 使用新的路由记录覆盖掉老的路由记录
//   router.matcher = newRouter.matcher; // reset router
// }

export default router
